﻿using CIS.Common.Dto.Dtos.Equipments.Commands;
using CIS.Server.Common.Entitys;
using CIS.Server.EQLinker;
using CIS.Server.Repository.PortRepository;
using MediatR;

namespace CIS.Server.Manager.Equipment
{
    public class EquipmentManager : IEquipmentManager
    {
        private readonly IPortRepository _portRepository;
        private readonly IMediator _mediator;

        public EquipmentManager(IPortRepository portRepository,IMediator mediator)
        {
            _portRepository = portRepository;
            _mediator = mediator;
        }


        #region Port 相关
        public async Task<PortEntity> GetPortByIdAsync(string portId)
        {
            PortEntity port =await _portRepository.GetByIdAsync(portId);
            return port;
        }

        public async Task<List<PortEntity>> GetPortsBySourceIdAsync(string portSourceId)
        {
            List<PortEntity> ports = await _portRepository.GetManyAsync(p=>p.QualifiedLocationId == portSourceId);
            return ports;
        }

        public async Task<List<PortEntity>> GetAllPortsAsync()
        {
            List<PortEntity> ports = await _portRepository.GetAllAsync();
            return ports;

        }

        public async Task<PortControlCommandDto> SendPortCommand(string sourceId, PortControlCommandDto command)
        {
            //var port = await _portRepository.GetByIdAsync(sourceId);


            return await _mediator.Send(command);
        }
        #endregion

    }
}
